<template></template>

<script>
import Vue from "vue";
export default {
    data() {
        return {
            isClicked: false,
            isPressing: false,
            ystStamp: null,
        };
    },
    created() {
        this.app.$on("refreshPage", (v) => {
            Vue.Native.callNative(
                "ConsoleModule",
                "log",
                `splash:---refreshPage`
            );
            this.refreshPage(v);
        });
        this.app.$on("onPreload", (v) => {
            Vue.Native.callNative("ConsoleModule", "log", `splash:onPreload`);
            // this.preloadData();
        });
        Vue.Native.callNative("ConsoleModule", "log", `splash:Store.getMsData`);
    },
    mounted() {
        // const aa = {"query":{"assortId":115,"programId":831890009,"uuid":"jslygxinwenzh","playType":"live","actionType":"全部频道"},"url":"/play"}
        const entryPage = this.app.$options.$superProps.entryPage;
        Vue.Native.callNative(
            "ConsoleModule",
            "log",
            `splash:mounted:${JSON.stringify(entryPage)}`
        );
        this.refreshPage(entryPage);
        // // const entryPage = JSON.stringify({ url: '/info', query: { id: 23287, title: '我的影子在奔跑', src: 'https://ft-oss.fangtangtv.com/ssp/license/video2.mp4' }})
        console.log("entryPage------", entryPage);
    },
    methods: {
        clickView() {
            this.isClicked = !this.isClicked;
        },

        onTouchBtnStart(evt) {
            console.log("onBtnTouchDown", evt);
            evt && evt.stopPropagation();
        },

        onTouchBtnMove(evt) {
            console.log("onBtnTouchMove", evt);
            evt && evt.stopPropagation();
            console.log(evt);
        },

        onTouchBtnEnd(evt) {
            console.log("onBtnTouchEnd", evt);
            evt && evt.stopPropagation();
            console.log(evt);
        },
        refreshPage(params) {
            console.log("params----传参", params);
            const entryPage = params;
            // const entryPage = "{\"psId\":\"3192007\",\"desktopId\":\"1570914997528166400\",\"url\":\"filtrate\",\"isDebugMode\":false}"
            if (entryPage) {
                try {
                    // Store.init(() => {
                    let paramsInfo = JSON.parse(entryPage);
                    // if (!__IS_DEV__ && paramsInfo?.url === '/home') {
                    //     Vue.Native.callNative(
                    //         "ConsoleModule",
                    //         "log",
                    //         `splash:refreshPage:${JSON.stringify(entryPage)}`
                    //     );
                    //     return
                    // }
                    const toPage = paramsInfo?.toPage;
                    paramsInfo.url = "/home";
                    if (paramsInfo.url) {
                        if (paramsInfo.query) {
                            // setFirstEntryPath(params.query);
                            this.$router.replace({
                                path: paramsInfo.url,
                                query: {
                                    ...paramsInfo.query,
                                    toPage
                                },
                            });
                        } else {
                            this.$router.replace({
                                path: paramsInfo.url,
                                query: {
                                    toPage
                                }
                            });
                            Vue.Native.callNative(
                                "ConsoleModule",
                                "log",
                                `splash:replace:${paramsInfo.url}`
                            );
                        }
                    }
                    // });
                    // const params = JSON.parse(entryPage)
                    // if (params.url) {
                    //   if (params.query) {
                    //     // setFirstEntryPath(params.query);
                    //     this.$router.replace({ path: params.url, query: params.query });
                    //   } else {
                    //     this.$router.replace(params.url);
                    //   }
                    // }
                } catch (error) {
                    Vue.Native.callNative(
                        "ConsoleModule",
                        "log",
                        `refreshPage:catch${JSON.stringify(error)}`
                    );
                    this.$router.replace("/home");
                }
            } else {
                this.$router.replace("/home");
            }
        },
    },
    beforeDestroy() {
        this.app.$off("refreshPage");
        this.app.$off("onPreload");
    },
};
</script>
